package com.mine.dubbo.common;

import com.mine.dubbo.netty.Client;
import com.mine.facade.model.Request;
import com.mine.facade.model.Response;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Component
@Log4j2
public class MyApplicationRunner implements ApplicationRunner {
    @Autowired
    private Client client;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("消费者启动成功");
        testSend();
    }

    public void testSend() {
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.execute(() -> {
            while (true) {
                log.info("将要发送请求");
                Response response = client.send(new Request(12, "123"));
                log.info(response);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        executorService.shutdown();
    }
}
